hud = { };

local function clr(color)
	return color.r, color.g, color.b, color.a;
end

function hud:PaintBar(x, y, w, h, colors, value)
	surface.SetDrawColor(clr(colors.border));
	surface.DrawOutlinedRect(x, y, w, h);
	
	x = x + 1;
	y = y + 1;
	w = w - 2;
	h = h - 2;
	
	surface.SetDrawColor(clr(colors.background));
	surface.DrawRect(x, y, w, h);
	
	local width = w * math.Clamp(value, 0, 1);
	local shade = 4;
	
	surface.SetDrawColor(clr(colors.shade));
	surface.DrawRect(x, y, width, shade);
	
	surface.SetDrawColor(clr(colors.fill));
	surface.DrawRect(x, y + shade, width, h - shade);
end

function hud:PaintPanel(x, y, w, h, colors)
	surface.SetDrawColor(clr(colors.border));
	surface.DrawOutlinedRect(x, y, w, h);
	
	x = x + 1;
	y = y + 1;
	w = w - 2;
	h = h - 2;
	
	surface.SetDrawColor(clr(colors.background));
	surface.DrawRect(x, y, w, h);
end

function hud:PaintText(x, y, text, font, colors)
	//surface.SetFont(font);
	
	surface.SetTextPos(x + 1, y + 1);
	surface.SetTextColor(clr(colors.shadow));
	surface.DrawText(text);
	
	surface.SetTextPos(x, y);
	surface.SetTextColor(clr(colors.text));
	surface.DrawText(text);
end

function paintHud()
	local colors = 
	{
		border = Color(255, 255, 255, 255),
		background = Color(255, 255, 255, 40),
		shade = Color(225, 225, 225, 180),
		fill = Color(0, 0, 0, 200),
		
		shadow = Color(0, 0, 0, 200),
		text = Color(150, 150, 150, 255)
	}

	//hud:PaintPanel(50, ScrH() - 84, 250, 34, colors);
	
	local core = LocalPlayer():GetNetworkedEntity("robot_core");
	local coreHealth = 0;
	local weight = 0;
	local max_weight = LocalPlayer():GetNetworkedInt("max_weight");
	if(ValidEntity(core)) then
		coreHealth = core:GetNetworkedInt("health");
		weight = core:GetNetworkedInt("weight");
	end
	
	draw.SimpleText("Robot Health", "ScoreboardText", 50, ScrH() - 60, colors.text, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
	hud:PaintBar(50, ScrH() - 50, 250, 16, colors, coreHealth);

	draw.SimpleText("Weight: " .. tostring(weight) .. "/" .. tostring(max_weight), "ScoreboardText", 200, ScrH() - 25, colors.text, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
	
	draw.SimpleText("Stage 1: Build", "ScoreboardText", 50, ScrH() - 25, colors.text, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
end

hook.Add("HUDPaint", "paintHud", paintHud);

function hideDefaultHud(name)
	for k, v in pairs{"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"} do
		if name == v then return false end
	end
end
hook.Add("HUDShouldDraw", "hideDefaultHud", hideDefaultHud);